/*
* @Author: Administrator
* @Date:   2018-01-04 14:20:36
* @Last Modified by:   Administrator
* @Last Modified time: 2018-01-09 16:23:13
*/
const webpack = require('webpack')
const path = require('path')
const fs = require('fs')
const express = require('express')

const serverConfig = require('../../webpack.server.config.js')
const bundleModule = require('../../dist/server/server.js')
const serverRender = require('../util/server_render')
const serverDist = (app) => {
  app.use('/dist', express.static(path.join(__dirname, '../../dist')))
  app.get('*', function (req, res, next) {
    const template = fs.readFileSync(path.join(__dirname, '../../dist/server_template.ejs'), 'utf-8')
    serverRender(bundleModule, template, req, res).catch(next)
  })
}

module.exports = serverDist
